#include <iostream>
#include "Win32Utils.hpp"

namespace vrts
{
	std::string Win32Utils::GetSelfModulePath()
	{

		MEMORY_BASIC_INFORMATION mbi;
		HMODULE hmod = NULL;
		if (::VirtualQuery(Win32Utils::GetSelfModulePath, &mbi, sizeof(mbi)) != 0)
		{
			hmod = (HMODULE)mbi.AllocationBase;
		}

		TCHAR fileName[512] = { 0 };
		GetModuleFileName(hmod, fileName, 512);

		std::string	 modName = fileName;

		return modName;
	}

	std::string Win32Utils::GetSelfModuleName()
	{

		MEMORY_BASIC_INFORMATION mbi;
		HMODULE hmod = NULL;
		if (::VirtualQuery(Win32Utils::GetSelfModuleName, &mbi, sizeof(mbi)) != 0)
		{
			hmod = (HMODULE)mbi.AllocationBase;
		}

		TCHAR fileName[512] = { 0 };
		GetModuleFileName(hmod, fileName, 512);

		std::string	 modPath = fileName;
		std::string  modName = modPath.substr(modPath.find_last_of("\\")+1, std::string::npos);

		return modName;
	}

	std::string Win32Utils::GetSelfModuleDir()
	{

		MEMORY_BASIC_INFORMATION mbi;
		HMODULE hmod = NULL;
		if (::VirtualQuery(Win32Utils::GetSelfModuleDir, &mbi, sizeof(mbi)) != 0)
		{
			hmod = (HMODULE)mbi.AllocationBase;
		}

		TCHAR fileName[512] = { 0 };
		GetModuleFileName(hmod, fileName, 512);

		std::string	 modName	= fileName;
		std::string  modDir		= modName.substr(0, modName.find_last_of("\\"));
		
		return modDir;
	}
	
}// namespace std
